<%--
  Created by IntelliJ IDEA.
  User: HP
  Date: 2021/8/24
  Time: 14:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<script src="${pageContext.request.contextPath}/jquery.js"></script>
<script>
    $(function () {
        var hid = $("#hid").val();
        $.ajax({
            url: "/hotevents/findId/" + hid,
            data: {},
            type: "POST",
            dataType: "JSON",
            success: function (data) {
                if (data.result == null) {
                    return
                }
                $("#sh1").html(data.result.keyWord)
                $("#createDate").html(data.result.createDate)
                $("#hotContent").html(data.result.hotContent);
                var div = "";
                for (var item of data.result.comments) {
                    div += "<div><span>" + item.content + "</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>" + item.commentDate + "</span></div>";
                }
                $("h2").after(div)
            }


        })

        $("#btnTest").click(function () {
            var content = $("#content").val().trim();
            if (content == "") {
                alert("评论内容不能为空");
                return;
            }
            $.ajax({
                url: "/comments/doAdd",
                data: {"content": $("#content").val(), "hid": $("#hid").val()},
                type: "POST",
                dataType: "JSON",
                success: function (data) {
                    var div = "";
                    if (data.result == 1) {
                        div = "<div><span>" + content + "</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>" + data.currentDate + "</span></div>";
                    } else {
                        alert("失败");
                    }
                    $("h2").after(div);
                }
            })
        })
    })


</script>
<head>
    <title>Title</title>
</head>
<body>

<h1 id="sh1"></h1>
创建于<h5 style="display: inline" id="createDate"></h5>
<p id="hotContent"></p>
<h2>评论</h2>
<input value="${id}" type="hidden" id="hid">
<textarea id="content" placeholder="请输入内容"></textarea>
<input type="button" id="btnTest" value="提交">
</body>
</html>
